#
# @lc app=leetcode.cn id=6 lang=python
#
# [6] Z 字形变换
#

# @lc code=start
class Solution(object):
    def convert(self, s, numRows):
        """
        :type s: str
        :type numRows: int
        :rtype: str
        """
        n = len(s)
        res = []
        for i in range(numRows):
            res.append(s[i])
            while i < n:
                i += 2*(numRows-i-1)
                if i < n:
                    res.append(s[i])
                i += 2*i
                if 2*i != 0 and i < n:
                    res.append(s[i])

a = Solution()
a.convert("PAYPALISHIRING",3)
# @lc code=end

